//
//  DownloadSubscriptionOperration.m
//  ABlip
//
//  Created by dawid on 09-02-13.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "DownloadSubscriptionOperration.h"
#import "BlipRequestUpdate.h"
#import "AppController.h"

@implementation DownloadSubscriptionOperration

- (void)dealloc {
	
    [super dealloc];
}

- (void)main {
  
	NSData *urlData;
	NSURLResponse *responce;
	NSError *error;
	NSURL *urlResp ;
	int tryCount = 3;
	BLP_URLRequestUpdate * request =[[BLP_URLRequestUpdate alloc] initWithSubscriptions:[[AppController shared] userPassword]];
	if (request == nil)
		return;
	while (tryCount >0){
		tryCount--;
		
		urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responce error:&error];
		if (!urlData){
#ifdef __DEBUG__
			NSLog(@"urlData=nil in sendRequest");
#endif
			continue;
		}
		break;
	}
	
	[urlResp release];
	urlResp =nil;
	
	[[AppController shared] performSelectorOnMainThread:@selector(readSubscriptions:)
											 withObject:urlData
										  waitUntilDone:YES];
    
}

@end
